#region using statements
using System;
using System.IO;
using System.Windows.Documents;
using System.Windows.Xps.Packaging;
using System.Windows.Media.Imaging;
using LIB = XPS2Image.Library; 
#endregion


namespace XPS2Image
{
    /// <summary>
    /// Main control loop for the XPS2Image application
    /// </summary>
    static public class XPS2ImageApplication
    {
        private class ShowHelpException : Exception {}
       
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        [STAThread()]
        public static void Main(string[] args)
        {
             try
             {
                 if (0 == args.Length)
                     throw new ShowHelpException();

                 foreach(string argument in args)
                 {
                     if ("-?" == argument)
                         throw new ShowHelpException();
                     if ("/?" == argument)
                         throw new ShowHelpException();
                     if ("-help" == argument)
                         throw new ShowHelpException();
                     if ("--help" == argument)
                         throw new ShowHelpException();
                 }

                 int[] pages = new int[] { 0 };

                 foreach(string argument in args)
                 {
                     LIB.FileConversions.SaveXpsPageToJpeg(argument, pages);
                 }

             }
             catch (ShowHelpException)
             {
                 Console.WriteLine("input like \"myfile\" ... that's all folks!");
             }
             catch(Exception ex)
             {
                 Console.WriteLine(string.Format("Error: {0}", ex.Message));
             }
        }
    }
}